package com.qinhao.loveCrowdFunding.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

public class TimeUtil {
    /** * 传入Data类型日期，返回字符串类型时间（ISO8601标准时间） * @param date * @return */
    public static String getISO8601Timestamp(Date date){
        long time = date.getTime() / 1000;
        time -= 1500;
        time *= 1000;
        date = new Date(time);
        TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
        // 2018-09-22T19:51:23+08:00
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+08:00'");
        df.setTimeZone(tz);
        String nowAsISO = df.format(date);
        return nowAsISO;
    }

    public static List<String> getMonitorLabels(Long[] timestamps) {
        List<String> labels = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < timestamps.length; i++) {
            Long timestamp = timestamps[i];
            timestamp = timestamp * 1000;
            String format = sdf.format(new Date(timestamp));
            labels.add(format);
            if (i == 4) {
                break;
            }
        }
       return labels;
    }
}
